﻿@model IEnumerable<OAWeb.Models.StudentScore>
@Scripts.Render("~/bundles/jquery")


@{

    for (int k = 0; k < ViewBag.grades.Length; k++)
    {
        for (int j = 0; j < ViewBag.cours.Length; j++)
        {

            ViewBag.scores[k, j] = Model.Single(g => g.StdNumber == ViewBag.grades[k].StudentID && g.CourseName == ViewBag.cours[j].Subject).Score;

        }

    }


}

<table class="table">
    <tr>
        <td>学号</td>
        <td>班级</td>
        <td>姓名</td>


        @for (int j = 0; j < ViewBag.cours.Length; j++)
        {
            <td> @ViewBag.cours[j].Subject</td>
        }

        <td>总分</td>
        <td>年级排名</td>
    </tr>

    @{






        string[,] s = new string[ViewBag.grades.Length, 7];
        double sum = 0;

        int e = 3;
        for (int i = 0; i < ViewBag.grades.Length; i++)
        {
            e = 3;
            double scoretotal = 0;


            for (int j = 0; j < ViewBag.cours.Length; j++)
            {


                scoretotal += ViewBag.scores[i, j];
            }

            sum = sum + scoretotal;


            s[i, 0] = ViewBag.scores1[i].Number.ToString();
            s[i, 1] = ViewBag.scores1[i].ClassName.ToString();
            s[i, 2] = ViewBag.scores1[i].Name.ToString();
            for (int i1 = 0; i1 < ViewBag.cours.Length; i1++)
            {
                s[i, 3 + i1] = ViewBag.scores[i, i1].ToString();
                e++;
            }

            s[i, e] = scoretotal.ToString();


        }


        for (int c = 0; c < ViewBag.grades.Length - 1; c++)
        {
            for (int a = 0; a < ViewBag.grades.Length - 1; a++)
            {
                if (int.Parse(s[a, e]) < int.Parse(s[a + 1, e]))
                {
                    for (int b = 0; b < ViewBag.cours.Length + 4; b++)
                    {
                        string[,] s1 = new string[ViewBag.grades.Length, ViewBag.cours.Length + 4];
                        s1[a, b] = s[a, b];
                        s[a, b] = s[a + 1, b];
                        s[a + 1, b] = s1[a, b];
                    }
                }
            }

        }
        int rand = 0;
        for (int i = 0; i < ViewBag.grades.Length; i++)
        {
            rand++;
            <tr>
                <td>@s[i, 0]</td>
                <td>@s[i, 1]</td>
                <td>@s[i, 2]</td>
                @for (int i1 = 0; i1 < ViewBag.cours.Length; i1++)
                {
                    <td>@s[i, 3 + i1]</td>

                }
                <td>@s[i, e]</td>
                <td>@rand</td>
            </tr>
        }


    }
</table>

